/**
 * 获取两个日期之间相差的天数
 * @param dateBegin 起始日期
 * @param dateEnd 结束日期
 * @return integer
 */
 export function difference(dateBegin, dateEnd) {
    var dateDiff = dateEnd.getTime() - dateBegin.getTime();//时间差的毫秒数
    var dayDiff = Math.ceil(dateDiff / (24 * 3600 * 1000));//计算出相差天数
    return dayDiff+1;
}

/**
 * 获取当前日期的上周一日期
 * @return date
 */
 export function getMonday() {
    var now = new Date();
    now.setDate(now.getDate()-7);
    var nowTime = now.getTime(); 
    var day = now.getDay();
    var oneDayTime = 24*60*60*1000;
    var MondayTime = nowTime - (day-1)*oneDayTime;
    var monday = new Date(MondayTime).toISOString().slice(0,10).replace(/-/g,"-");
    return monday;
}

/**
 * 获取当前日期的上周日日期
 * @return date
 */
 export function getSunday() {
    var now = new Date(); 
    now.setDate(now.getDate()-7);
    var nowTime = now.getTime(); 
    var day = now.getDay();
    var oneDayTime = 24*60*60*1000;
    var SundayTime =  nowTime + (7-day)*oneDayTime;
    var sunday = new Date(SundayTime).toISOString().slice(0,10).replace(/-/g,"-");
    return sunday;
}
/**
 * 获取当前日期的上月日日期
 * @return date
 */
 export function getlastMonthStr() {
    let now = new Date();
    // 当前月的日期
    let nowDate = now.getDate();
    let lastMonth = new Date(now.getTime());
    // 设置上一个月（这里不需要减1）
    lastMonth.setMonth(lastMonth.getMonth());
    // 设置为0，默认为当前月的最后一天
    lastMonth.setDate(0);
    // 上一个月的天数
    let daysOflastMonth = lastMonth.getDate();
    // 设置上一个月的日期，如果当前月的日期大于上个月的总天数，则为最后一天 
    lastMonth.setDate(nowDate > daysOflastMonth ? daysOflastMonth : nowDate);
    var dateStr = lastMonth.toISOString().slice(0,10).replace(/-/g,"-");
    return dateStr;
}
export function getCurMonthStr() {
    let now = new Date();
    let rtn = now.getMonth()+1;
    return rtn+'月'
}
export function getDateStr(theDate) {
    var dateStr = theDate.toISOString().slice(0,10).replace(/-/g,"-");
    return dateStr;
}
export function getDaysPriorDateStr(theDate, days) {
    theDate.setDate(theDate.getDate()-days);
    var dateStr = theDate.toISOString().slice(0,10).replace(/-/g,"-");
    return dateStr;
}
export function getDaysLateDateStr(theDate, days) {
    theDate.setDate(theDate.getDate()+days);
    var dateStr = theDate.toISOString().slice(0,10).replace(/-/g,"-");
    return dateStr;
}
export function getWeekDateAry() {
    let date1 = getDaysPriorDateStr(new Date(),6);
    let date2 = getDaysPriorDateStr(new Date(),5);
    let date3 = getDaysPriorDateStr(new Date(),4);
    let date4 = getDaysPriorDateStr(new Date(),3);
    let date5 = getDaysPriorDateStr(new Date(),2);
    let date6 = getDaysPriorDateStr(new Date(),1);
    let date7 = getDateStr(new Date());
    let weekAry = [date1, date2, date3, date4, date5, date6, date7];
    return weekAry;
}
export function getMonthDateAry() {
    let date30 = getDaysPriorDateStr(new Date(),29);
    let date29 = getDaysPriorDateStr(new Date(),28);
    let date28 = getDaysPriorDateStr(new Date(),27);
    let date27 = getDaysPriorDateStr(new Date(),26);
    let date26 = getDaysPriorDateStr(new Date(),25);
    let date25 = getDaysPriorDateStr(new Date(),24);
    let date24 = getDaysPriorDateStr(new Date(),23);
    let date23 = getDaysPriorDateStr(new Date(),22);
    let date22 = getDaysPriorDateStr(new Date(),21);
    let date21 = getDaysPriorDateStr(new Date(),20);
    let date20 = getDaysPriorDateStr(new Date(),19);
    let date19 = getDaysPriorDateStr(new Date(),18);
    let date18 = getDaysPriorDateStr(new Date(),17);
    let date17 = getDaysPriorDateStr(new Date(),16);
    let date16 = getDaysPriorDateStr(new Date(),15);
    let date15 = getDaysPriorDateStr(new Date(),14);
    let date14 = getDaysPriorDateStr(new Date(),13);
    let date13 = getDaysPriorDateStr(new Date(),12);
    let date12 = getDaysPriorDateStr(new Date(),11);
    let date11 = getDaysPriorDateStr(new Date(),10);
    let date10 = getDaysPriorDateStr(new Date(),9);
    let date9 = getDaysPriorDateStr(new Date(),8);
    let date8 = getDaysPriorDateStr(new Date(),7);
    let date7 = getDaysPriorDateStr(new Date(),6);
    let date6 = getDaysPriorDateStr(new Date(),5);
    let date5 = getDaysPriorDateStr(new Date(),4);
    let date4 = getDaysPriorDateStr(new Date(),3);
    let date3 = getDaysPriorDateStr(new Date(),2);
    let date2 = getDaysPriorDateStr(new Date(),1);
    let date1 = getDateStr(new Date());
    let monthAry = [date30, date29, date28, date27, date26, date25, date24, date23, date22, date21, date20, date19, date18, date17, date16, date15, date14, date13, date12, date11, date10, date9, date8, date7, date6, date5, date4, date3, date2, date1];
    return monthAry;
}
export function getParamQueryString(url, name) {
    let subStr = name + '='
    if (url.indexOf(subStr) !== -1) {
        let arr = url.split(subStr)
        let sub1 = arr[1]
        if (sub1.indexOf('&') !== -1) {
        let arr2 = sub1.split('&')
        let sub2 = arr2[0]
            return sub2
        } else {
            return sub1
        }
    }
    return ''
}
export function HashMap(){  
    //定义长度  
    var length = 0;  
    //创建一个对象  
    var obj = new Object();  
  
    /** 
    * 判断Map是否为空 
    */  
    this.isEmpty = function(){  
        return length == 0;  
    };  
  
    /** 
    * 判断对象中是否包含给定Key 
    */  
    this.containsKey=function(key){  
        return (key in obj);  
    };  
  
    /** 
    * 判断对象中是否包含给定的Value 
    */  
    this.containsValue=function(value){  
        for(var key in obj){  
            if(obj[key] == value){  
                return true;  
            }  
        }  
        return false;  
    };  
  
    /** 
    *向map中添加数据 
    */  
    this.put=function(key,value){  
        if(!this.containsKey(key)){  
            length++;  
        }  
        obj[key] = value;  
    };  
  
    /** 
    * 根据给定的Key获得Value 
    */  
    this.get=function(key){  
        return this.containsKey(key)?obj[key]:null;  
    };  
  
    /** 
    * 根据给定的Key删除一个值 
    */  
    this.remove=function(key){  
        if(this.containsKey(key)&&(delete obj[key])){  
            length--;  
        }  
    };  
  
    /** 
    * 获得Map中的所有Value 
    */  
    this.values=function(){  
        var _values= new Array();  
        for(var key in obj){  
            _values.push(obj[key]);  
        }  
        return _values;  
    };  
  
    /** 
    * 获得Map中的所有Key 
    */  
    this.keySet=function(){  
        var _keys = new Array();  
        for(var key in obj){  
            _keys.push(key);  
        }  
        return _keys;  
    };  
  
    /** 
    * 获得Map的长度 
    */  
    this.size = function(){  
        return length;  
    };  
  
    /** 
    * 清空Map 
    */  
    this.clear = function(){  
        length = 0;  
        obj = new Object();  
    };  
} 